﻿Chenxin.UI.IncomeDetailsOwner = Chenxin.extend(Chenxin.UI.PageCommon, {
    autoInitForm: false,
    actionUrl: '/service/Reports/IncomeDetailsOwner.ashx',
    createSearch: function() {
        return new Chenxin.UI.IncomeDetailsOwnerSearch({
            scope: this
        });
    },
    createGrid: function() {
		_this = this;
        return new Chenxin.UI.JsonGrid({
			createTitleTool:function(){					
				return [{
					text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
					scope:this,
					title:'导出全部数据',
					handler:function(el){
						_this.exportAll();
					}
				}];
			},
            actionUrl: this.actionUrl + '?op=getlist',
            pageSize: 50,
            height:400,
            renderTo: 'divShowBalanceList',
            hasCheckBox: false,
            scope: this,
            autoLoad: false,
            id: 'BalanceList',
            title: '实收明细表',
            scope: this,
            columns: {
                business: {
                    width: 122,
                    head: "商圈",
                    sortable: true
                },
                departname: {
                    width: 180,
                    head: "部门",
                    sortable: true
                },

                ContractCode: {
                    width: 140,
                    head: "成交编号",
                    sortable: true
                },
                ContractDate: {
                    width: 80,
                    head: "成交日期",
                    sortable: true
                },
                HouseAddress: {
                    width: 300,
                    head: "地址",
                    sortable: true
                },
                PointEmp: {
                    width: 100,
                    head: "业务员",
                    sortable: true
                },
                DeparterManagerName: {
                    width: 100,
                    head: "店长",
                    sortable: true
                },
                MangerName: {
                    width: 100,
                    head: "高级经理",
                    sortable: true
                },
                RegionManagerName: {
                    width: 100,
                    head: "区域经理",
                    sortable: true
                },
                MajordomoName: {
                    width: 100,
                    head: "总监",
                    sortable: true
                },
                StanCommision: {
                    width: 80,
                    head: "标准佣收"
                },
                RealCommisionFinal: {
                    width: 80,
                    head: "应收佣收",
                    sortable: true
                },
                CommisionFinal: {
                    width: 80,
                    head: "折佣",
                    sortable: true
                },
                ConsultingFinal: {
                    width: 80,
                    head: "咨询费",
                    sortable: true
                },
                Point: {
                    width: 80,
                    head: "点数",
                    sortable: true
                },
                PayMoney: {
                    width: 80,
                    head: "实收",
                    sortable: true
                },
                ApportionRealCommisionFinal: {
                    width: 80,
                    head: "分配应收佣收",
                    sortable: true
                },
                ApportionCommisionFinal: {
                    width: 80,
                    head: "分配折佣",
                    sortable: true
                },
                ApportionConsultingFinal: {
                    width: 80,
                    head: "分配咨询费",
                    sortable: true
                },
                ApportionPay: {
                    width: 80,
                    head: "分配实收",
                    sortable: true
                },
                PayDate: {
                    width: 80,
                    head: "收款日期",
                    sortable: true
                },
                PayArchDate: {
                    width: 80,
                    head: "实收归属日期",
                    sortable: true,
                    renderer: function(val, field, row) {
                        if (val.indexOf('.') >= 0) {
                            return val.substring(0, 4) + '年' + val.substring(5.1) + '月';
                        }
                        else {
                            return '';
                        }
                    }
                },
                ContractArchDate: {
                    width: 80,
                    head: "业绩归属日期",
                    sortable: true
                },
                BargainCompanyName: {
                    width: 80,
                    head: "合同归属公司",
                    sortable: true
                }
            }
        });
    },
	exportAll:function(){
	    _this = this;
	    paramStr = this.search.getParamJson();
	    paramStr.op = 'exportAll';
	    Chenxin.Msg.Waiting.show();
	    Chenxin.Fn.exportToExcelByServer(this.actionUrl, paramStr, '导出文件');
	    //$.ajax({ url: this.actionUrl, data: paramStr,async:false});
	    Chenxin.Msg.Waiting.hide();
	}
});

/*
* 查询面板
*/
Chenxin.UI.IncomeDetailsOwnerSearch = Chenxin.extend(Chenxin.UI.SearchCommon, {
    id: 'divCondition',
    createComboList: function() {
		
        //人员
        this.comboUserId = new Chenxin.UI.RichModelTreeCombo({
            textBoxId: 'txtUser',
            inModelType: 'all',
            txtModelName: 'UserName',
            singleSelect: true,
            name: 'UserId'
        });
		
		var _this=this;
        this.combl = new Chenxin.UI.StructComboList({
            cityAfterSelected: function() {
                _this.comboUserId.reset();
            },
            companyAfterSelected: function() {
                _this.comboUserId.reset();
            },
            businessDistrictAfterSelected: function() {
                _this.comboUserId.reset();
            },
            departsAfterSelected: function(val) {
                _this.comboUserId.reset();
                if (val != '请选择') {
                    _this.comboUserId.loadUser(val, 500);
                }
            }
        });
        var structs = this.combl.comboList;
        structs.push(this.comboUserId);

        return structs;
    },
    initEvent: function() {
        $("#txtStartTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        }).defText({
            deftxt: '开始时间'
        });

        $("#txtEndTime").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM-dd',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        }).defText({
            deftxt: '结束时间'
        });

        var curdate = new Date();
        $('#txtActualDate').val(curdate.getFullYear() + '-' + (curdate.getMonth() + 1));
		
        $("#txtActualDate").focus(function() {
            WdatePicker({
                dateFmt: 'yyyy-MM',
                oncleared: function() {
                    $(this).blur();
                },
                onpicked: function() {
                    $(this).blur();
                }
            });
        });
		
        $("#txtKeyword").defText({
            deftxt: '成交编号/房源地址'
        });
		
		$('.x_type').bind('click',{scope:this},function(e){
			var fn=this.value=='10'?'setEnable':'setDisable';
			e.data.scope.combl.businessDistrict[fn]();
			e.data.scope.combl.departs[fn]();
			e.data.scope.comboUserId[fn]();
			
			e.data.scope.combl.businessDistrict.reset();
			e.data.scope.combl.departs.reset();
			e.data.scope.comboUserId.reset();
		});

        var objSrh = this;
        /*********事件：检索按钮*********/
        $("#btSearch").click(function() {
            objSrh.scope.reloadGrid();
        });
    }
});

getcity = true; //设置需要获取城市下拉框数据

$(function() {
    var objPg = new Chenxin.UI.IncomeDetailsOwner();
});